package com.hh.TreeQuestions;


import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author hanghao
 * @Date 2023/7/3 14:27
 * @Version 1.0
 * 对称二叉树
 * easy
 */

public class No101 {
    public boolean isSymmetric(TreeNode root) {
        return compare(root.left, root.right);
    }
    public boolean compare(TreeNode left, TreeNode right) {
        if (left == null && right != null) return false;
        if (right == null && left != null) return false;
        if (right == null && left == null) return true;
        if (right.val != left.val) {
            return false;
        }
        //注意: 这个一定不能写的 因为判断出相同就直接返回true 不会进行后面的判断了
//        if (right.val == left.val) {
//            return true;
//        }
        // 比较外侧
        boolean compareOutside = compare(left.left, right.right);
        // 比较内侧
        boolean compareInside = compare(left.right, right.left);
        //本质上也是后续遍历
        return compareOutside && compareInside;
    }
}
